﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core;
using Cofe.Core.Filter;
using Cofe.Core.Implements;
using Cofe.Data.Utils.ThirdParty;

namespace Cofe.Data.Filter
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFEDB)]
    public class GuidEntryFilterExpression : 
        IEntryFilterExpression<GuidEntryFilter>
    {
        public Expression<Func<CofeSystemInfo, bool>>
            GetQueryExpression(GuidEntryFilter entryFilter, IOptionFilter[] options)
        {            
            Guid lookupId = new Guid(entryFilter.Value);

            var propExpr = CofeServices.PropertyDictionary.GetPropertyExpression<Guid>(CacheProperties.Id);
            var exp = LambaUtils.EqualExpr<Guid>(propExpr, lookupId);
      
            if (entryFilter.Negative)
                return exp.Not();
            return exp;
        }
    }
}
